/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ADT;
import Interfaces.Length;

/**
 *
 * @author markusbaisch
 */
public class LengthImpl extends Values implements Length {

    private final double meters;

    // Konstruktor
    private LengthImpl(double meters) {
        this.meters = meters;
    }

    @Override
    public double m() {
        return meters;
    }

    @Override
    public double ft() {
        return meters / FEET_IN_METERS;
    }

    @Override
    public Length add(Length Value) {
        return valueOf( meters + Value.m() );
    }

    @Override
    public Length sub(Length Value) {
        return valueOf( meters - Value.m() );
    }

    @Override
    public Length mul(double faktor) {
        return valueOf( meters * faktor );
    }

    @Override
    public Length div(double faktor) {
        return valueOf( meters / faktor );
    }

    @Override
    public double div(Length Value) {
        return meters / Value.m();
    }

    @Override
    public Length inverse() {
        return new LengthImpl(meters * -1.0);
    }

    @Override
    public boolean isZero() {
        return (meters == 0.0);
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public int compareTo(Length Value) {
        return Double.compare( meters, Value.m() );
    }

    //@Override
    public static Length valueOf(double Value) {
        return new LengthImpl( Value );
    }

    @Override
    public double getValue() {
        return meters;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) return true;
        if (!(o instanceof LengthImpl)) return false;
        return this.compareTo((LengthImpl) o) == 0;
    }

    @Override
    public int hashCode(){
        return hashDouble( meters );
    }

}
